import request from '@/utils/request'
import { filtersRaw, pageRequsetBody } from '@/utils'
// 送装服务接口

/* 系统使用情况相关接口*/

// 办事处列表(部分)
export function getOffice() {
  return request({
    url: '/call-center/api/v1/reportSystemUse',
    method: 'get'
  })
}

// 系统使用情况导出(部分)
export function exportSystemUse(data) {
  return request({
    url: '/call-center/api/v1/reportSystemUse/export',
    method: 'post',
    responseType: 'blob',
    data
  })
}
// 系统使用情况导出(全部)
export function exportSystemUseAll(data) {
  return request({
    url: '/call-center/api/v1/reportSystemUse/exportAll',
    method: 'post',
    responseType: 'blob',
    data
  })
}
// 系统使用情况明细导出(部分)
export function exportSystemUseDetail(data) {
  return request({
    url: '/call-center/api/v1/reportSystemUse/export/detail',
    method: 'post',
    responseType: 'blob',
    data
  })
}
// 系统使用情况明细导出(全部)
export function exportSystemUseDetailAll(data) {
  return request({
    url: '/call-center/api/v1/reportSystemUse/exportAll/detail',
    method: 'post',
    responseType: 'blob',
    data
  })
}

/* 服务详情接口 */

// 服务详情导出(全部)
export function exportServiceDetaillAll(data) {
  return request({
    url: '/call-center/api/v1/reportServiceDetail/exportAll',
    method: 'post',
    responseType: 'blob',
    data
  })
}

// 服务详情导出(分页)
export function exportServiceDetaill(data) {
  return request({
    url: '/call-center/api/v1/reportServiceDetail/export',
    method: 'post',
    responseType: 'blob',
    data
  })
}

/* 送装服务订单完成情况报表*/
// 导出(全部)
export function exportOrderCompletionAll(data) {
  return request({
    url: '/call-center/api/v1/reportOrderCompletion/exportAll',
    method: 'post',
    responseType: 'blob',
    data
  })
}
// 导出(分页)
export function exportOrderCompletion(data) {
  return request({
    url: '/call-center/api/v1/reportOrderCompletion/export',
    method: 'post',
    responseType: 'blob',
    data
  })
}

export function getWinningDetail(winningCode) {
  const data = {
    pageFlag: false,
    filtersRaw: [
      filtersRaw('winningCode', winningCode, '=')
    ]
  }
  return request({
    url: '/call-center/api/v1/careTask/page',
    method: 'POST',
    data: pageRequsetBody(data)
  }).then(res => {
    if (res.data.records.length > 0) {
      return res.data.records[0]
    } else {
      return Promise.reject()
    }
  })
}

// 系统完成情况
// 办事处
export function pageOffice(filtersRaw = [], otherRaw = {}, pageFlag = true) {
  const data = {
    pageFlag,
    rows: 20,
    paramsRaw: otherRaw,
    filtersRaw: filtersRaw
  }
  return request({
    url: '/call-center/api/v1/reportSystemUse/pageOffice',
    method: 'POST',
    data: pageRequsetBody(data)
  }).then(res => {
    return res.data.records
  })
}

// 获取经销商 /api/v1/reportSystemUse/pageDealer
export function pageDealer(filtersRaw = [], otherRaw = {}) {
  const data = {
    pageFlag: true,
    rows: 20,
    paramsRaw: otherRaw,
    filtersRaw: filtersRaw
  }
  return request({
    url: '/call-center/api/v1/reportSystemUse/pageDealer',
    method: 'POST',
    data: pageRequsetBody(data)
  }).then(res => {
    return res.data.records
  })
}

// 订单完成情况
// 办事处
export function pageOrderDoneOffice(filtersRaw = [], otherRaw = {}) {
  const data = {
    pageFlag: true,
    rows: 20,
    paramsRaw: otherRaw,
    filtersRaw: filtersRaw
  }
  return request({
    url: '/call-center/api/v1/reportOrderCompletion/pageOffice',
    method: 'POST',
    data: pageRequsetBody(data)
  }).then(res => {
    return res.data.records
  })
}

// 获取经销商
export function pageOrderDoneDealer(filtersRaw = [], otherRaw = {}) {
  const data = {
    pageFlag: true,
    rows: 20,
    paramsRaw: otherRaw,
    filtersRaw: filtersRaw
  }
  return request({
    url: '/call-center/api/v1/reportOrderCompletion/pageDealer',
    method: 'POST',
    data: pageRequsetBody(data)
  }).then(res => {
    return res.data.records
  })
}

// 送装明细
// 办事处
export function pageOrderDetailOffice(filtersRaw = [], otherRaw = {}, pageFlag = true) {
  const data = {
    pageFlag,
    rows: 20,
    paramsRaw: otherRaw,
    filtersRaw: filtersRaw
  }
  return request({
    url: '/call-center/api/v1/reportServiceDetail/pageOffice',
    method: 'POST',
    data: pageRequsetBody(data)
  }).then(res => {
    return res.data.records
  })
}

// 获取经销商
export function pageOrderDetailDealer(filtersRaw = [], otherRaw = {}) {
  const data = {
    pageFlag: true,
    rows: 20,
    paramsRaw: otherRaw,
    filtersRaw: filtersRaw
  }
  return request({
    url: '/call-center/api/v1/reportServiceDetail/pageDealer',
    method: 'POST',
    data: pageRequsetBody(data)
  }).then(res => {
    return res.data.records
  })
}

// 启用评价指标
export function enableIndex(selected) {
  return request({
    url: '/call-center/api/v1/appraise/appraiseIndex/enabled',
    method: 'PUT',
    data: {
      id: selected.map(e => e.id).join(',')
    }
  })
}
// 停用评价指标
export function disableIndex(selected) {
  return request({
    url: '/call-center/api/v1/appraise/appraiseIndex/disable',
    method: 'PUT',
    data: {
      id: selected.map(e => e.id).join(',')
    }
  })
}
// 新增评价指标
export function addAppraiseIndex(data) {
  return request({
    url: '/call-center/api/v1/appraise/appraiseIndex',
    method: 'POST',
    data
  })
}
// 修改评价指标
export function editAppraiseIndex(data) {
  return request({
    url: '/call-center/api/v1/appraise/appraiseIndex',
    method: 'PUT',
    data
  })
}
// 获取所有指标
export function appraiseIndexAll() {
  return request({
    url: '/call-center/api/v1/appraise/appraiseIndex/',
    method: 'GET'
  })
}
// 分页获取指标
export function appraiseIndexPage() {
  const data = new FormData()
  data.append('pageFlag', false)
  return request({
    url: '/call-center/api/v1/appraise/appraiseIndex/page',
    method: 'POST',
    data
  })
}

// 标签新增
export function addAppraiseTag(data) {
  return request({
    url: '/call-center/api/v1/appraise/appraiseTag/',
    method: 'POST',
    data
  })
}
// 标签编辑
export function editAppraiseTag(data) {
  return request({
    url: '/call-center/api/v1/appraise/appraiseTag/',
    method: 'PUT',
    data
  })
}
// 启用标签
export function enableTag(selected) {
  return request({
    url: '/call-center/api/v1/appraise/appraiseTag/enabled',
    method: 'PUT',
    data: {
      id: selected.map(e => e.id).join(',')
    }
  })
}
// 停用标签
export function disableTag(selected) {
  return request({
    url: '/call-center/api/v1/appraise/appraiseTag/disable',
    method: 'PUT',
    data: {
      id: selected.map(e => e.id).join(',')
    }
  })
}

// 评分
export function companyAppraise(data) {
  return request({
    url: '/call-center/api/v1/appraise/companyAppraise',
    method: 'PUT',
    data
  })
}

// 下载图片
export function exportDataToFile(path, method = 'post', params, name) {
  return request({
    url: path + '?fileName=' + name,
    method,
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/json'
    },
    data: params
  })
}

// 订单完成情况统计表  公司评分
export function appraiseResultInfo(data) {
  return request({
    url: '/call-center/api/v1/appraiseResultInfo',
    method: 'post',
    data
  })
}
